package com.example.cslp.controller;

import com.example.cslp.pojo.entity.Course;
import com.example.cslp.service.CourseServiceByYh;
import com.example.cslp.util.TimeUtil;
import com.example.cslp.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController//表明是控制类
@RequestMapping("/course")//声明目录
@ResponseBody
public class CourseControllerByYh {
    @Autowired
    public CourseServiceByYh courseServiceByYh;
    TimeUtil timeUtil=new TimeUtil();
    //创建课程
    @RequestMapping("/createCourse")
    public JsonResult createCourse(@RequestBody Course course){
        //导入建立时间
        TimeUtil timeUtil=new TimeUtil();
        course.setUploadTime(timeUtil.getCurrentTimePlus());
        System.out.println(course.getUploadTime());
        return JsonResult.ok(courseServiceByYh.createCourse(course),"创建课程成功");
    }

    //查询课程列表
    @RequestMapping("/queryAllCourse")
    public  JsonResult queryAllCourse(){
        return JsonResult.ok(courseServiceByYh.findAllCourse(),"获取课程列表成功");
    }

    //编辑课程
    @RequestMapping("/editCourse")
    public JsonResult editCourse(@RequestBody Course course){
        //编辑课程也更新编辑时间
        course.setUploadTime(timeUtil.getCurrentTimePlus());
        return JsonResult.ok(courseServiceByYh.editCourse(course),"编辑成功");
    }

    //删除课程
    @RequestMapping("/deleteCourse")
    public JsonResult deleteCourse(@RequestParam String courseId){
        System.out.println(courseId);
        return JsonResult.ok(courseServiceByYh.deleteCourse(courseId),"删除成功");
    }
    //审核用户上传的资料
    @RequestMapping("/examMaterial")
    public JsonResult examMaterial(@RequestBody Course course){
        //更新审核时间
        course.setReviewTime(timeUtil.getCurrentTimePlus());
        return JsonResult.ok(courseServiceByYh.examMaterial(course),"修改审核状态成功");
    }
}
